package com.teach.hotel;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/**
 * <pre>
 * 客户
 * ClassName : com.teach.User
 * Author : J.L.Zhou
 * Date : 2019年6月2日 下午4:44:08
 * Version : V1.0
 * Copyright 2019 jlzhou.top Inc. All rights reserved. 
 * 注意：本内容仅限于公司内部传阅，禁止外泄以及用于其他的商业目</pre>
 */
public class User {
	
	public static List<User> users = new ArrayList<>();
	public static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");

	private String idcard;
	private String name;
	private Boolean isMember;
	private String tel;
	private Date brithdate;
	private List<Record> list;
	
	public String getIdcard() {
		return idcard;
	}
	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Boolean getIsMember() {
		return isMember;
	}
	public void setIsMember(Boolean isMember) {
		this.isMember = isMember;
	}
	public String getTel() {
		return tel;
	}
	public void setTel(String tel) {
		this.tel = tel;
	}
	public Date getBrithdate() {
		return brithdate;
	}
	public void setBrithdate(Date brithdate) {
		this.brithdate = brithdate;
	}
	public List<Record> getList() {
		return list;
	}
	public void setList(List<Record> list) {
		this.list = list;
	}
	
	
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((idcard == null) ? 0 : idcard.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		User other = (User) obj;
		if (idcard == null) {
			if (other.idcard != null)
				return false;
		} else if (!idcard.equals(other.idcard))
			return false;
		return true;
	}
	
	
	@Override
	public String toString() {
		return "---------用户信息----------\n\t身份证：" + idcard + "\n\t姓名：" + name + "\n\t会员：" + (isMember?"是":"否") + "\n\t电话：" + tel + "\n\t生日："
				+ format.format(brithdate)+"\n------------------------";
	}
	/**
	 * 添加or选择用户
	 * @return
	 */
	public static User addOrSelect(){
		Scanner in = new Scanner(System.in);
		System.out.println("请输入身份证号码:");
		String idcard = in.next();
		User u = new User();
		u.setIdcard(idcard);
		int index = users.indexOf(u);
		if(index>-1){
			return users.get(index);
		}else{
			System.out.println("请输入姓名：");
			u.setName(in.next());
			System.out.println("请输入电话号码：");
			u.setTel(in.next());
			System.out.println("请输入出生日期：");
			try{
				u.setBrithdate(format.parse(in.next()));
			}catch(Exception e){
				u.setBrithdate(new Date());
			}
			System.out.println("请输入是否是会员：(y/n)");
			u.setIsMember(in.next().equalsIgnoreCase("y"));
			users.add(u);
			return u;
		}
	}
	
	
}
